#!/bin/bash

source ./env

if [ "$#" -ne 1 ]
then
    echo "参数错误！(-cdl: c=conf d=data l=logs)"
    exit 1
fi

echo '正在初始化环境'
# 设置家目录
home=$ALBERTMU_WORKSPACE
if [[ -d $home ]]; then
    echo "初始化环境失败，文件夹【${home}】已存在。"
    exit 1
fi
# 创建家文件夹、配置文件夹和数据文件夹
mkdir $home
if [[ $1 =~ 'c' ]]; then
    mkdir $home/conf
fi
if [[ $1 =~ 'd' ]]; then
    mkdir $home/data
fi
if [[ $1 =~ 'l' ]]; then
    mkdir $home/logs
fi
echo '初始化成功'
echo '正在部署容器'
# 启动docker容器
docker run -d --name $ALBERTMU_C_NAME \
 --privileged=true \
 --restart=always \
 --net $VNET_NAME \
 -p $ALBERTMU_HOST_PORT:$ALBERTMU_C_PORT \
 -v ${home}/data:/data \
 -v ${home}/conf:/conf \
 -v ${home}/logs:/datalog \
 -e TZ=Asia/Shanghai \
 $ALBERTMU_IMAGE_NAME:$ALBERTMU_VERSION
echo "${ALBERTMU_IMAGE_NAME}已安装！"
